﻿using Devonline.AspNetCore;
using Microsoft.Extensions.DependencyInjection;

namespace Devonline.CloudService.Aliyun;

public static class ServiceExtensions
{
    /// <summary>
    /// 注册短消息服务
    /// </summary>
    /// <param name="services"></param>
    /// <param name="endpoint"></param>
    /// <param name="smsModel"></param>
    /// <returns></returns>
    public static IServiceCollection AddSmsService(this IServiceCollection services, ISmsEndpoint? endpoint = default, SmsModel? smsModel = default)
    {
        if (endpoint is not null && smsModel is not null)
        {
            services.AddSingleton(endpoint);
            services.AddSingleton(smsModel);
            services.AddSingleton<ISmsService<SmsModel>, SmsService>();
        }

        return services;
    }
}